package leetcode.L130;

class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        //对于每行，二分查找
        for (int[] ints : matrix) {
            int index = search(ints,target);
            if (index>=0) {
                return true;
            }
        }
        return false;
    }

    public int search(int[] row,int target) {
        int len = row.length;
        int low = 0;
        int high = len - 1;
        while (low <= high) {//low不能大于high，可以等于
            int mid = (high - low) / 2 + low;
            if (row[mid]==target) {
                return mid;
            } else if (row[mid] > target) {
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        return -1;
    }
}